﻿using System;
using System.Windows.Forms;
using Map;

namespace Map_Creator
{
    public partial class ObjectEditor : Form
    {
        public ObjectData Data;
        public ObjectEditor(ObjectData data)
        {
            InitializeComponent();
            
            Data = data ?? new ObjectData();

            foreach (var pair in Data)
            {
                dataGridView1.Rows.Add(new[] {pair.Key, pair.Value});
            }
        }

        private void CancelButton_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
            Close();
        }

        private void OkButton_Click(object sender, EventArgs e)
        {
            Data = new ObjectData();
            foreach (DataGridViewRow row in dataGridView1.Rows)
            {
                var name = row.Cells["NameColumn"].Value;
                var data = row.Cells["DataColumn"].Value;
                if (name == null || data == null) continue;
                Data.Add(name.ToString(), data.ToString());
            }

            DialogResult = DialogResult.OK;
            Close();
        }
    }
}
